*/}}
Browse Source

Adapt to windows VC

ChengduLittleA 9 months ago
parent
commit
2cf1f1ab5b
3 changed files with 45 additions and 14 deletions
  1. 23 11
      CMakeLists.txt
  2. 17 3
      example_viewer.c
  3. 5 0
      luajit.c

+ 23 - 11
CMakeLists.txt

@@ -6,6 +6,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR})
 find_package(lagui REQUIRED)
 find_package(LuaJIT OPTIONAL_COMPONENTS)
 
+add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
+add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
+
 include_directories(
     ${LAGUI_INCLUDE_DIRS_ALL}
 )
@@ -61,16 +64,25 @@ endif()
 
 target_link_libraries(example_viewer ${LAGUI_SHARED_LIBS} )
 
+get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
+if(GENERATOR_IS_MULTI_CONFIG)
+set(INSTALL_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>)
+else()
+set(INSTALL_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
+
 add_custom_command(
     TARGET example_viewer POST_BUILD
-    COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/example_source_files
-    COMMAND cp ${CMAKE_SOURCE_DIR}/luajit.c        ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/luajit.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/nvgtest.c        ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/nvgtest.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/calculator.c     ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/calculator.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/widgets.c        ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/widgets.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/widget_flags.c   ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/widget_flags.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/fruits.c         ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/fruits.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/modelling_main.c ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/modelling_main.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/simple_properties.c ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/simple_properties.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/operator.c       ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/operator.c
-    COMMAND cp ${CMAKE_SOURCE_DIR}/simplest.c       ${CMAKE_CURRENT_BINARY_DIR}/example_source_files/simplest.c)
+    COMMAND ${CMAKE_COMMAND} -E make_directory ${INSTALL_CONFIG_PATH}/example_source_files
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/luajit.c         ${INSTALL_CONFIG_PATH}/example_source_files/luajit.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/nvgtest.c        ${INSTALL_CONFIG_PATH}/example_source_files/nvgtest.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/calculator.c     ${INSTALL_CONFIG_PATH}/example_source_files/calculator.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/widgets.c        ${INSTALL_CONFIG_PATH}/example_source_files/widgets.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/widget_flags.c   ${INSTALL_CONFIG_PATH}/example_source_files/widget_flags.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/fruits.c         ${INSTALL_CONFIG_PATH}/example_source_files/fruits.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/modelling_main.c ${INSTALL_CONFIG_PATH}/example_source_files/modelling_main.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/simple_properties.c ${INSTALL_CONFIG_PATH}/example_source_files/simple_properties.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/operator.c       ${INSTALL_CONFIG_PATH}/example_source_files/operator.c
+    COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/simplest.c       ${INSTALL_CONFIG_PATH}/example_source_files/simplest.c
+)

+ 17 - 3
example_viewer.c

@@ -277,13 +277,24 @@ Lua is a lightweight scripting language, by using LuaJIT FFI, you can call C run
 
 int inv_LaunchDemo(laOperator* a, laEvent* e){
     char* program=strGetArgumentString(a->ExtraInstructionsP,"program"); if(!program) return LA_FINISHED;
-    char command[512]; sprintf(command,"./%s &",program);
+    char command[512];
+#ifdef _WIN32
+    sprintf(command, "start /b ./%s.exe", program);
+#endif
+#ifdef __linux__
+    sprintf(command,"./%s &",program);
+#endif
     system(command);
     return LA_FINISHED;
 }
 int inv_OpenDemoSource(laOperator* a, laEvent* e){
     char* file=strGetArgumentString(a->ExtraInstructionsP,"file"); if(!file) return LA_FINISHED;
-    char command[512]; sprintf(command,"xdg-open example_source_files/%s &",file);
+#ifdef _WIN32
+    char command[512]; sprintf(command, "start \"\" example_source_files/%s &", file);
+#endif
+#ifdef __linux__
+    char command[512]; sprintf(command, "xdg-open example_source_files/%s &", file);
+#endif
     system(command);
     return LA_FINISHED;
 }
@@ -365,7 +376,10 @@ int main(int argc, char *argv[]){
     laGetReady();
 
     char buf[512];getcwd(buf,512);
-    printf("%s\n",buf);
+    char* exedir=argv[0]; int len=strlen(exedir);
+    for(int i=len-1;i>=0;i--){ if(exedir[i]=='/'||exedir[i] == '\\'){exedir[i]=0;break;} }
+    chdir(exedir);
+    printf("%s %s\n",buf,exedir);
 
     InitExamples();
 

+ 5 - 0
luajit.c

@@ -23,7 +23,12 @@
 #include "lualib.h"
 #include "luajit.h"
 
+#ifdef __linux__
 #include <dlfcn.h>
+#endif
+#ifdef _WIN32
+#include <Windows.h>
+#endif
 
 STRUCTURE(MyData){
     int _pad;