diff --git a/CMakeLists.txt b/CMakeLists.txt index 3259a9ce..78e9f545 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,8 @@ else() option(PK_BUILD_STATIC_LIB "Build static library" ON) endif() +option(PK_BUILD_STATIC_MAIN "Build static main" OFF) + if(PK_BUILD_SHARED_LIB) message(">> Building shared library") add_library(${PROJECT_NAME} SHARED ${POCKETPY_SRC}) @@ -68,8 +70,13 @@ elseif(PK_BUILD_STATIC_LIB) message(">> Building static library") add_library(${PROJECT_NAME} STATIC ${POCKETPY_SRC}) else() - message(">> Building shared library + executable") - add_library(${PROJECT_NAME} SHARED ${POCKETPY_SRC}) + if(PK_BUILD_STATIC_MAIN) + message(">> Building static library + executable") + add_library(${PROJECT_NAME} STATIC ${POCKETPY_SRC}) + else() + message(">> Building shared library + executable") + add_library(${PROJECT_NAME} SHARED ${POCKETPY_SRC}) + endif() add_executable(main src2/main.c) target_link_libraries(main ${PROJECT_NAME}) endif() diff --git a/cmake_build.py b/cmake_build.py index 925fd4b6..c0636544 100644 --- a/cmake_build.py +++ b/cmake_build.py @@ -7,28 +7,36 @@ assert os.system("python prebuild.py") == 0 if not os.path.exists("build"): os.mkdir("build") -assert len(sys.argv) <= 2 +# python cmake_build.py [Debug|Release|RelWithDebInfo] ... -if len(sys.argv) == 2: +if len(sys.argv) > 1: config = sys.argv[1] else: config = 'Release' +extra_flags = " ".join(sys.argv[2:]) + assert config in ['Debug', 'Release', 'RelWithDebInfo'] os.chdir("build") -code = os.system(f"cmake .. -DPK_ENABLE_OS=ON -DCMAKE_BUILD_TYPE={config}") +code = os.system(f"cmake .. -DPK_ENABLE_OS=ON -DCMAKE_BUILD_TYPE={config} {extra_flags}") assert code == 0 code = os.system(f"cmake --build . --config {config}") assert code == 0 if sys.platform == "win32": shutil.copy(f"{config}/main.exe", "../main.exe") - shutil.copy(f"{config}/pocketpy.dll", "../pocketpy.dll") + dll_path = f"{config}/pocketpy.dll" + if os.path.exists(dll_path): + shutil.copy(dll_path, "../pocketpy.dll") elif sys.platform == "darwin": shutil.copy("main", "../main") - shutil.copy("libpocketpy.dylib", "../libpocketpy.dylib") + dll_path = "libpocketpy.dylib" + if os.path.exists(dll_path): + shutil.copy(dll_path, "../libpocketpy.dylib") else: shutil.copy("main", "../main") - shutil.copy("libpocketpy.so", "../libpocketpy.so") + dll_path = "libpocketpy.so" + if os.path.exists(dll_path): + shutil.copy(dll_path, "../libpocketpy.so")